package com.dsbj.it.DingTalkBotStarter.common.converter;

import com.dsbj.it.DingTalkBotStarter.common.enums.FieldTypeEnum;

/**
 * 整数类型转换器
 */
public class IntegerConverter implements TypeConverter {
    @Override
    public Object convert(String value) {
        if (value == null || value.trim().isEmpty()) {
            return null;
        }
        try {
            return Integer.parseInt(value.trim());
        } catch (NumberFormatException e) {
            throw new RuntimeException("无法将值 '" + value + "' 转换为整数", e);
        }
    }

    @Override
    public FieldTypeEnum getSupportedType() {
        return FieldTypeEnum.INTEGER;
    }
}


